<template>
  <span class="setting">
    <div class="setting__shade"
         :class="{'setting__shade--show':isShade}"
         @click="close"></div>
    <i class="el-icon-more setting__icon"
       @click="open"></i>

      <div class="setting__content"
           :class="{'setting__content--show':box}">
<!--
        <div class="setting__header">&lt;!&ndash;版权信息&ndash;&gt;</div>
-->
        <!--<div class="setting__body setting__about">
          about
          &nbsp;&nbsp;&nbsp;&nbsp;
        </div>-->
        <div class="setting__header">设置
<!--
          <small>(滑动鼠标下面还有更多设置)</small>
-->
        </div>
        <!--<el-tooltip v-if="showColor"
                  effect="dark"
                  content="主题色"
                  placement="bottom">
        <div class="top-bar__item">
          <top-color></top-color>
        </div>
      </el-tooltip>-->

      <el-tooltip v-if="showLock"
                  effect="dark"
                  content="锁屏"
                  placement="bottom">
        <div class="top-bar__item">
          <top-lock></top-lock>
        </div>
      </el-tooltip>
      <el-tooltip v-if="showTheme"
                  effect="dark"
                  content="特色主题"
                  placement="bottom">
        <div class="top-bar__item top-bar__item--show">
          <top-theme></top-theme>
        </div>


      </el-tooltip>
        <!--
      <el-tooltip v-if="showDebug"
                  effect="dark"
                  :content=""
                  placement="bottom">
        <div class="top-bar__item">
          <top-logs></top-logs>
        </div>
      </el-tooltip>-->
      </div>
  </span>
</template>

<script>
    import {mapState, mapGetters} from 'vuex'
    import {validatenull} from '@/util/validate'
    import {option, list} from '@/const/setting/'

    import {fullscreenToggel, listenfullscreen} from "@/util/util";
    import topLock from "./top-lock";
    import topMenu from "./top-menu";
    import topSearch from './top-search';
    import topBreadcrumb from "./top-breadcrumb";
    import topColor from "./top-color";
    import topTheme from "./top-theme";
    import topLogs from "./top-logs";
    import topSetting from "./top-setting";
    import topMsg from "./top-msg";

    export default {
        components: {topLock, topMenu, topSearch, topBreadcrumb, topColor, topTheme, topLogs, topSetting, topMsg},
        data() {
            return {
                box: false,
                form: {},
                list: list,
                option: option(this)
            }
        },
        computed: {
            ...mapGetters(['isShade']),
            ...mapState({
                showTag: state => state.common.showTag,
                showDebug: state => state.common.showDebug,
                showLock: state => state.common.showLock,
                showColor: state => state.common.showColor,
                showFullScren: state => state.common.showFullScren,
                showCollapse: state => state.common.showCollapse,
                showSearch: state => state.common.showSearch,
                showMenu: state => state.common.showMenu,
                showTheme: state => state.common.showTheme
            })

        },
        mounted() {
            listenfullscreen(this.setScreen);
        },
        created() {
            this.init();
        },
        methods: {

            setScreen() {
                this.$store.commit("SET_FULLSCREN");
            },
            handleScreen() {
                fullscreenToggel();
            },
            close() {
                this.box = false;
                this.$store.commit('SET_SHADE', false);
            },
            set(key) {
                const ele = this.find(key);
                this.$store.commit(ele.commit, eval(this.form[ele.key]));
            },
            find(key) {
                return this.list.filter(ele => ele.key === key)[0]
            },
            init() {
                this.list.forEach(ele => {
                    this.form[ele.key] = validatenull(this[ele.key]) ? 'true' : this[ele.key] + '';
                    this.set(ele.key);
                })
            },
            open() {
                this.box = true;
                this.$store.commit('SET_SHADE', true);
            }
        }
    }
</script>

<style lang="scss" scoped>
    .setting {
        margin-left: 10px;

        &__icon {
            transform: rotate(90deg);
        }

        &__header {
            height: 42px;
            line-height: 42px;
            padding: 0 15px;
            border-bottom: 1px solid #f6f6f6;
            color: #333;
            border-radius: 2px 2px 0 0;
            font-size: 14px;

            small {
                margin-left: 8px;
                color: #999;
            }
        }

        &__body {
            padding: 10px 15px;
            line-height: 24px;
        }

        &__about {
            font-size: 14px;
            line-height: 30px;
        }

        &__shade {
            position: fixed;
            display: none;
            width: 100%;
            height: 100%;
            left: 0;
            right: 0;
            top: 0;
            bottom: 0;
            background-color: rgba(0, 0, 0, 0.3);
            z-index: 2048;

            &--show {
                display: block;
            }
        }

        &__form {
            width: 230px;
            margin: 0 auto;
        }

        &__content {
            box-shadow: 1px 1px 10px rgba(0, 0, 0, 0.1);
            transition: all 0.3s;
            position: fixed;
            width: 320px;
            height: 100%;
            right: -450px;
            top: 0;
            z-index: 2048;
            background-color: #fff;

            &--show {
                right: 0;
            }
        }
    }
</style>
